package smetana.modules.io.dbfimpot;

import com.google.common.collect.ImmutableList;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
* @author dmitry.mamonov
*/
public class ExternalModel {
    Map<String, ExternalAgents> agentsMap = new LinkedHashMap<String, ExternalAgents>();
    Map<String, ExternalBrigaders> brigadersMap = new LinkedHashMap<String, ExternalBrigaders>();
    List<ExternalDocumin> documinList = new ArrayList<ExternalDocumin>();
    Map<String, ExternalDocument> documentMap = new LinkedHashMap<String, ExternalDocument>();
    Map<String, ExternalGoods> goodsMap = new LinkedHashMap<String, ExternalGoods>();

    public void addAgents(ExternalAgents agents) {
        agentsMap.put(agents.getCode(), agents);
    }

    public void addBrigaders(ExternalBrigaders brigaders) {
        brigadersMap.put(brigaders.getCodeb(), brigaders);
    }

    public void addDocumin(ExternalDocumin documin){
        documinList.add(documin);

    }

    public void addDocument(ExternalDocument document){
        documentMap.put(document.getProvn(),document);
    }

    public void addGoods(ExternalGoods goods){
        //System.out.println(goods);
        String key = goods.getCode_t();
        if (goodsMap.containsKey(key)){
            System.out.println("duplcate: "+goods);
        }
        goodsMap.put(key,goods);

    }

    public List<ExternalAgents> listAgents() {
        return ImmutableList.copyOf(agentsMap.values());
    }

    public List<ExternalBrigaders> listBrigaders(){
        return ImmutableList.copyOf(brigadersMap.values());
    }

    public List<ExternalGoods> listGoods() {
        return ImmutableList.copyOf(goodsMap.values());
    }

    public List<ExternalDocument> listDocuments(){
        return ImmutableList.copyOf(documentMap.values());
    }

    public List<ExternalDocumin> listDocumins(){
        return ImmutableList.copyOf(documinList);
    }

    public ExternalGoods getGoods(String code_t) {
        return goodsMap.get(code_t);
    }
}
